<html>
<head>
<title>Iron Puzzler {{ game.location }}</title>
<link rel="stylesheet" href="static/style.css">
</head>
<body>

<div class="pageheader"><img src="static/banner.png"/></div>

<div class="pagecontent">

{% if game.login_enabled %}
<form action="/login" method="post">
<h3>{{ game.location }} team:
<select name="t">
  {% for team in teams|dictsort:"name" %}
    <option {% if team.key == cookie_team.key %} selected {% endif %}
            value="{{ team.key_id }}">{{ team.name }}</option>
  {% endfor %}
</select>
<label>password:
<input type="password" name="pw" value="{{ cookie_password }}" size=10></label>
<button type="submit">Login</button>
</h3></form>
{% endif %}

{% if admin_email %}
<p><a href="/admin">Administrator</a>: {{ admin_email }}
(<a href="{{ admin_logout_url }}">sign out</a>)</p>
{% endif %}

{% if game.results_enabled or admin_email %}
  {% if game.results_enabled %}
    <h3>Final results</h3>
  {% else %}
    <h3>PRELIMINARY results (admin only)</h3>
  {% endif %}

  <table>
    <tr>
      <td> </td>
      <td align="center"><b>Total</b></td>
      <td align="center">Solving</td>
      <td align="center">Voting</td>
      <td align="center">Bonus</td>
    </tr>
    {% for team in teams|dictsort:"score" reversed %}
      <tr {% if team.key == cookie_team.key %} class="your_team" {% endif %}>
        <td><nobr>{{ forloop.counter }}. {{ team.name }}</nobr></td>
        <td align="center"><b>{{ team.score }}</b></td>
        <td align="center">{{ team.solve_score }}</td>
        <td align="center">{{ team.wrote_score }}</td>
        <td align="center">{{ team.bonus }}</td>
      </tr>
    {% endfor %}
  </table>

  <h3>Results: Solving</h3>

  {% regroup puzzles by key_name as puzzle_types %}

  <table>
    <tr>
      <td> </td>
      <td align="center"><b>Total</b></td>
      {% for type in puzzle_types %}
        <td class="score_{{ type.grouper }}"> </td>
        <td align="center" colspan="{{ type.list|length }}"
            class="score_{{ type.grouper }}">
          <b>{{ type.grouper|capfirst }}</b>
        </td>
        <td> </td>
      {% endfor %}
    </tr>

    <tr>
      <td colspan="2"> </td>
      {% for type in puzzle_types %}
        <td class="score_{{ type.grouper }}"> </td>
        {% for puzzle in type.list %}
          <td align="center" class="score_{{ type.grouper }}" title="#{{ puzzle.number }} &quot;{{ puzzle.title }}&quot; by {{ puzzle.author }}">
            <em>#{{ puzzle.number }}</em>
          </td>
        {% endfor %}
        {% if not forloop.last %} <td> </td> {% endif %}
      {% endfor %}
    </tr>

    {% for team in teams|dictsort:"solve_score" reversed %}
      {% regroup team.works by puzzle.key_name as work_types %}
      <tr {% if team.key == cookie_team.key %} class="your_team" {% endif %}>
        <td><nobr>{{ team.name }}</nobr></td>

        <td align="center"><b>{{ team.solve_score }}</b></td>

        {% for type in work_types %}
          <td class="score_{{ type.grouper }}"> </td>
          {% for work in type.list %}
            {% if work.puzzle.author_id == team.key_id %}
              <td align="center" class="score_{{ type.grouper }}" title="{{ team.name }} wrote #{{ work.puzzle.number }} &quot;{{ work.puzzle.title }}&quot;"> A </td>
            {% else %} {% if work.score %}
              <td align="center" class="score_{{ type.grouper }}" title="{{ team.name }} earned {{ work.score }} points for solving&#10;#{{ work.puzzle.number }} &quot;{{ work.puzzle.title }}&quot; {{ work.solve_time|timesince }} ago">
                {{ work.score }}
              </td>
            {% else %}
              <td align="center" class="score_{{ type.grouper }}"> -- </td>
            {% endif %} {% endif %}
          {% endfor %}
          {% if not forloop.last %} <td> </td> {% endif %}
        {% endfor %}
      </tr>
    {% endfor %}
  </table>

  <h3>Results: Voting</h3>

  <table>
    <tr>
      <td> </td>
      <td align="center"><b>Total</b></td>

      <td class="score_paper"> </td>
      <td align="center" class="score_paper" colspan="4"><b>Paper</b></td>
      <td> </td>

      <td class="score_nonpaper"> </td>
      <td align="center" class="score_nonpaper" colspan="4"><b>Nonpaper</b></td>
    </tr>

    <tr>
      <td colspan="2"> </td>

      <td class="score_paper"> </td>
      <td align="center" class="score_paper"><em>Fun(&#215;2)</em></td>
      <td align="center" class="score_paper"><em>Pres.</em></td>
      <td align="center" class="score_paper"><em>Ingr.</em></td>
      <td align="center" class="score_paper"><em>Score</em></td>
      <td> </td>

      <td class="score_nonpaper"> </td>
      <td align="center" class="score_nonpaper"><em>Fun(&#215;2)</em></td>
      <td align="center" class="score_nonpaper"><em>Pres.</em></td>
      <td align="center" class="score_nonpaper"><em>Ingr.</em></td>
      <td align="center" class="score_nonpaper"><em>Score</em></td>
    </tr>

    {% for team in teams|dictsort:"wrote_score" reversed %}
      <tr {% if team.key == cookie_team.key %} class="your_team" {% endif %}>
        <td><nobr>{{ team.name }}</nobr></td>

        <td align="center"><b>{{ team.wrote_score }}</b></td>

        <td class="score_paper"> </td>
        <td align="center" class="score_paper" title="{{ team.name }} earned {{ team.wrote.paper.scores.0 }} (&#215;2)&#10;Fun points for #{{ team.wrote.paper.number }} &quot;{{ team.wrote.paper.title }}&quot;">{{ team.wrote.paper.scores.0 }}&#215;2</td>
        <td align="center" class="score_paper" title="{{ team.name }} earned {{ team.wrote.paper.scores.1 }} &#10;Presentation points for #{{ team.wrote.paper.number }} &quot;{{ team.wrote.paper.title }}&quot;">{{ team.wrote.paper.scores.1 }}</td>
        <td align="center" class="score_paper" title="{{ team.name }} earned {{ team.wrote.paper.scores.2 }} &#10;Ingredients points for #{{ team.wrote.paper.number }} &quot;{{ team.wrote.paper.title }}&quot;">{{ team.wrote.paper.scores.2 }}</td>
        <td align="center" class="score_paper" title="{{ team.name }} earned {{ team.wrote.paper.score }} &#10;total points for #{{ team.wrote.paper.number }} &quot;{{ team.wrote.paper.title }}&quot;">{{ team.wrote.paper.score }}</td>
        <td> </td>

        <td class="score_nonpaper"> </td>
        <td align="center" class="score_nonpaper" title="{{ team.name }} earned {{ team.wrote.nonpaper.scores.0 }} (&#215;2)&#10;Fun points for #{{ team.wrote.nonpaper.number }} &quot;{{ team.wrote.nonpaper.title }}&quot;">{{ team.wrote.nonpaper.scores.0 }}&#215;2</td>
        <td align="center" class="score_nonpaper" title="{{ team.name }} earned {{ team.wrote.nonpaper.scores.1 }} &#10;Presentation points for #{{ team.wrote.nonpaper.number }} &quot;{{ team.wrote.nonpaper.title }}&quot;">{{ team.wrote.nonpaper.scores.1 }}</td>
        <td align="center" class="score_nonpaper" title="{{ team.name }} earned {{ team.wrote.nonpaper.scores.2 }} &#10;Ingredients points for #{{ team.wrote.nonpaper.number }} &quot;{{ team.wrote.nonpaper.title }}&quot;">{{ team.wrote.nonpaper.scores.2 }}</td>
        <td align="center" class="score_nonpaper" title="{{ team.name }} earned {{ team.wrote.nonpaper.score }} &#10;total points for #{{ team.wrote.nonpaper.number }} &quot;{{ team.wrote.nonpaper.title }}&quot;">{{ team.wrote.nonpaper.score }}</td>
      </tr>
    {% endfor %}
  </table>

  <h3>Generosity (FYI)</h3>

  <table>
    <tr>
      <td> </td>

      <td class="score_paper"> </td>
      <td align="center" class="score_paper" colspan="3"><b>Paper</b></td>
      <td> </td>

      <td class="score_nonpaper"> </td>
      <td align="center" class="score_nonpaper" colspan="3"><b>Nonpaper</b></td>
    </tr>

    <tr>
      <td> </td>

      <td class="score_paper"> </td>
      <td align="center" class="score_paper"><em>Fun</em></td>
      <td align="center" class="score_paper"><em>Pres.</em></td>
      <td align="center" class="score_paper"><em>Ingr.</em></td>
      <td> </td>

      <td class="score_nonpaper"> </td>
      <td align="center" class="score_nonpaper"><em>Fun</em></td>
      <td align="center" class="score_nonpaper"><em>Pres.</em></td>
      <td align="center" class="score_nonpaper"><em>Ingr.</em></td>
    </tr>

    {% for team in teams|dictsort:"name" %}
      <tr {% if team.key == cookie_team.key %} class="your_team" {% endif %}>
        <td><nobr>{{ team.name }}</nobr></td>

        <td class="score_paper"> </td>
        <td align="center" class="score_paper" title="{{ team.name }} gave out {{ team.generosity.paper.0|default:"no" }} Fun points">{{ team.generosity.paper.0|default:"--" }}</td>
        <td align="center" class="score_paper" title="{{ team.name }} gave out {{ team.generosity.paper.1|default:"no" }} Presentation points">{{ team.generosity.paper.1|default:"--" }}</td>
        <td align="center" class="score_paper" title="{{ team.name }} gave out {{ team.generosity.paper.2|default:"no" }} Ingredients points">{{ team.generosity.paper.2|default:"--" }}</td>
        <td> </td>

        <td class="score_nonpaper"> </td>
        <td align="center" class="score_nonpaper" title="{{ team.name }} gave out {{ team.generosity.nonpaper.0|default:"no" }} Fun points">{{ team.generosity.nonpaper.0|default:"--" }}</td>
        <td align="center" class="score_nonpaper" title="{{ team.name }} gave out {{ team.generosity.nonpaper.1|default:"no" }} Presentation points">{{ team.generosity.nonpaper.1|default:"--" }}</td>
        <td align="center" class="score_nonpaper" title="{{ team.name }} gave out {{ team.generosity.nonpaper.2|default:"no" }} Ingredients points">{{ team.generosity.nonpaper.2|default:"--" }}</td>
      </tr>
    {% endfor %}
  </table>
{% endif %}

{% if game.solving_enabled %}
  <h3>Standings</h3>

  <table>
    {% for team in teams %}
      <tr {% if team.key == cookie_team.key %} class="your_team" {% endif %}>
        <td><nobr>{{ forloop.counter }}. {{ team.name }}</nobr></td>
        <td>
          {{ team.solve_count|default:"no" }}
          solve{{ team.solve_count|pluralize }}
        </td>
        <td>
          {% if team.solve_time %}
            {{ team.solve_time|timesince }} ago
          {% endif %}
        </td>
      </tr>
    {% endfor %}
  </table>
{% endif %}

{% if game.ingredients_visible %}
  <h3>Secret ingredients</h3>
  {% for ingredient in game.ingredients %}
    <h4>{{ ingredient }}</h4>
  {% endfor %}
{% endif %}

<h3>About</h3>

<p><a href="http://www.ironpuzzler.com/">Iron Puzzler</a> is a weekend contest
where teams create puzzles on the first day and solve puzzles on the second
day.  This website tracks progress in {{ game.location }}.</p>

</div>  <!-- end .pagecontent -->

</body>
</html>
